// lib/widgets/fixed_top_arc_border.dart

import 'package:flutter/material.dart';

/// 一个自定义的 ShapeBorder，用于绘制一个固定宽度的、开口朝上的弧线。
class TopArcBorder extends ShapeBorder {
  final Color borderColor;
  final double borderWidth;
  final double arcWidth;

  const TopArcBorder({
    this.borderColor = Colors.black,
    this.borderWidth = 2.0,
    this.arcWidth = 30.0,
  });

  @override
  EdgeInsetsGeometry get dimensions => EdgeInsets.zero;

  @override
  Path getInnerPath(Rect rect, {TextDirection? textDirection}) {
    return Path();
  }

  @override
  Path getOuterPath(Rect rect, {TextDirection? textDirection}) {
    final Path path = Path();
    final double centerX = rect.center.dx;
    final double startX = centerX - (arcWidth / 2);
    final double endX = centerX + (arcWidth / 2);

    final Offset startPoint = Offset(startX, rect.bottom);
    final Offset endPoint = Offset(endX, rect.bottom);

    path.moveTo(startPoint.dx, startPoint.dy);

    // 5. 使用 arcToPoint 绘制一个弧线到终点
    //    【核心改动】: 增大了半径，使弧线不再是半圆，而是更平缓的浅弧。
    //    一个常用的值是直接使用 arcWidth 作为半径，这样弧度看起来很舒服。
    //    你可以调整这个值，值越大，弧线越平。
    path.arcToPoint(
      endPoint,
      radius: Radius.circular(arcWidth), // <--- 改动在这里！从 arcWidth / 2 改为 arcWidth
      clockwise: false,
    );

    return path;
  }

  @override
  void paint(Canvas canvas, Rect rect, {TextDirection? textDirection}) {
    final Paint paint = Paint()
      ..color = borderColor
      ..style = PaintingStyle.stroke
      ..strokeWidth = borderWidth;

    canvas.drawPath(getOuterPath(rect, textDirection: textDirection), paint);
  }

  @override
  ShapeBorder scale(double t) => this;
}
